package com.jch.dm.chapter_15_facade.pagemaker;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

/**
 * @author: Administrator
 * 使用Database类和HtmlWrite类生成指定用户的Web页面
 * @create: 2020/04/05 16:08
 **/
public class PageMaker {

    /**
     * 防止外部new出PageMaker的实例
     */
    private PageMaker(){}

    public static void makeWelcomePage(String mailaddr,String filename){
        try {
            Properties mailprop = Database.getProperties("maildata");
            String username = mailprop.getProperty(mailaddr);
            HtmlWriter writer = new HtmlWriter(new FileWriter(filename));
            writer.title("Welcome to " + username + "'s page!");
            writer.paragraph(username+"欢迎来到"+username+"的主页。");
            writer.paragraph("等你的邮件！");
            writer.mailto(mailaddr,username);
            writer.close();
            System.out.println(filename+" is created for "+mailaddr+" ("+username+")");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
